package org.adorsys.aderp.aderplogin.client;

import javax.servlet.http.HttpServletRequest;

import org.adorsys.aderp.aderplogin.client.hessian.AbstractPreAuthenticatedProcessingFilter2;
import org.adorsys.aderp.aderplogin.client.oauth.OauthClientTokenProvider;

public class OauthPreAuthFilter extends
		AbstractPreAuthenticatedProcessingFilter2 {

	private OauthClientTokenProvider oauthTokenProvider;

	@Override
	protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) {
		return oauthTokenProvider.getOAuth2AccessToken();
	}

	
	/**
	 * Also return the access token. Null will lead o the faillure of the 
	 * authentication.
	 */
	@Override
	protected Object getPreAuthenticatedCredentials(HttpServletRequest request) {
		return oauthTokenProvider.getOAuth2AccessToken();
	}


	public void setOauthTokenProvider(OauthClientTokenProvider oauthTokenProvider) {
		this.oauthTokenProvider = oauthTokenProvider;
	}

	@Override
	public void afterPropertiesSet() {
		if(oauthTokenProvider==null) throw new IllegalStateException("oauthTokenProvider must be set");
		super.afterPropertiesSet();
	}

}
